<template>
  <div class="form_box">
    <avue-form :option="option" v-model="crudData.form" @submit="handleSubmit">
      <template #channel_currency_to_system_currency_rate>
        <el-input v-model="crudData.form.channel_currency_to_system_currency_rate"
                  placeholder="通道币与系统币汇率"
                  class="input-with-select">
          <template #prepend>
            $
          </template>
        </el-input>
      </template>
    </avue-form>
  </div>
</template>
<script setup>
import {configList, configPut} from "@/api/user/index.js";
import {ElMessage} from "element-plus";
import {onMounted} from "vue";

let props = defineProps({
  content: {
    type: Object,
    default: () => [],
    required: true
  }
})
const crudData = reactive({
  form: {},
  nowData: {},
})
const option = reactive({
  labelWidth: 200,
  size: 'medium',
  column: [
    {
      label: '开启充值',
      prop: 'enable_recharge',
      type: 'switch',
      dicData: [{
        label: '',
        value: '0'
      }, {
        label: '',
        value: '1'
      }],
      span: 24,
    },
    {
      label: '开启提现',
      prop: 'enable_withdrawal',
      type: 'switch',
      span: 24,
      dicData: [{
        label: '',
        value: '0'
      }, {
        label: '',
        value: '1'
      }],
    },

    // {
    //   label: '货币名称',
    //   prop: 'currency_name',
    //   span: 24,
    //   prefixIcon: 'el-icon-edit',

    // },
    {
      label: '通道币与系统币汇率',
      prop: 'channel_currency_to_system_currency_rate',
      span: 24,
      prefixIcon: 'icon-zhuti',
    },
    {
      label: '提现手续费',
      prop: 'withdrawal_fee',
      type: 'textarea',
      span: 24,

    },
    {
      label: '提现充值说明',
      prop: 'withdrawal_recharge_instructions',
      type: 'textarea',
      span: 24,
    },
    {
      label: '提现时间',
      prop: 'timerange',
      type: 'timerange',
      format: 'HH:mm:ss',
      valueFormat: 'HH:mm:ss',
      startPlaceholder: '时间开始范围自定义',
      endPlaceholder: '时间结束范围自定义',

    },
  ]
})
const handleSubmit = (form, done) => {
  let params = {}
  params.sunpay = form
  if (form.timerange && form.timerange.length > 0) {
    params.sunpay.withdrawal_start_time = form.timerange[0]
    params.sunpay.withdrawal_end_time = form.timerange[1]
  }
  delete params.sunpay.timerange
  console.log('form', params)
  configPut(params).then(res => {
    ElMessage.success('操作成功')
    initData()
  }).catch(err => {
  })
  done()
}
const initData = async () => {
  await configList().then(res => {
    crudData.form = res.data.sunpay
    crudData.form.timerange = [res.data.sunpay.withdrawal_start_time, res.data.sunpay.withdrawal_end_time]
  })
}
onMounted(() => {
  initData()
})
</script>
<style scoped lang="scss">
.form_box {
  width: 100%;
  padding: 0 20px 20px 20px;
  height: calc(100vh - 120px);
  overflow-y: auto;

  ::v-deep .avue-form {
    .el-collapse-item__wrap {
      padding: 20px;
    }
  }
}

::v-deep .el-input-group__prepend {
  padding: 0 15px;
}
</style>
